# make file for uCos-ii skyeye LPC21XX
#
#  version : 1.0 ( Max Lv max.c.lv@gmail.com)
#

# if you use arm-elf-gcc in linux environment
CROSS_COMPILE 	= arm-elf-
#if you use arm-linux-gcc in cygwin environment
#CROSS_COMPILE 	= arm-linux-

CC		= $(CROSS_COMPILE)gcc
AS		= $(CROSS_COMPILE)gcc
AR		= $(CROSS_COMPILE)ar
LD		= $(CROSS_COMPILE)ld	
NM		= $(CROSS_COMPILE)nm
OBJDUMP		= $(CROSS_COMPILE)objdump
READELF		= $(CROSS_COMPILE)readelf
RM		= rm -f
RN		= mv
BIN		= $(CROSS_COMPILE)objcopy


TRG	= ucos-lpc
TRGDIR	= .
LSTDIR  = .
INCDIR	= .
LIB 	= -L/usr/local/lib/gcc-lib/arm-elf/2.95.3/ -lgcc -lc
SHELL   = /bin/sh

###############################################################################

CFLAGS = -c -Wall -I./boot -I./lib -O2 -pipe -g -mapcs-32 -march=armv4 -mtune=arm7tdmi -mshort-load-bytes 
ASFLAGS = -c -D__ASSEMBLY__ -DNO_MM -g -mapcs-32 -marmv4 -msoft-float -mno-fpu -I./boot 
LDFLAGS = -nostdlib -Bstatic -Tucos-lpc.lds

###############################################################################

START_OBJ = startup.o 

OBJS = target.o irq.o os_cpu_c.o os_cpu_a.o os_core.o os_mbox.o os_mutex.o os_sem.o os_time.o os_men.o os_q.o os_task.o os_flag.o main.o uart0.o queue.o skyeye_printf.o skyeye_stdio.o


###############################################################################

all: ucos-lpc.elf

test: all
	skyeye -e ucos-lpc.elf

skyeye_printf.o:lib/skyeye_printf.c lib/skyeye_stdio.h
	$(CC) $(CFLAGS) lib/skyeye_printf.c
skyeye_stdio.o:lib/skyeye_stdio.c lib/skyeye_stdio.h
	$(CC) $(CFLAGS) lib/skyeye_stdio.c
main.o:user/main.c
	$(CC) $(CFLAGS) user/main.c
startup.o:boot/startup.s
	$(AS) $(ASFLAGS) boot/startup.s
target.o:boot/target.c boot/target.h
	$(CC) $(CFLAGS) boot/target.c
irq.o:lpc/irq.s
	$(AS) $(ASFLAGS) lpc/irq.s
os_cpu_c.o:lpc/os_cpu_c.c
	$(CC) $(CFLAGS) lpc/os_cpu_c.c
os_cpu_a.o:lpc/os_cpu_a.s
	$(AS) $(ASFLAGS) lpc/os_cpu_a.s
os_core.o:kernel/os_core.c
	$(CC) $(CFLAGS) kernel/os_core.c
os_mbox.o:kernel/os_mbox.c
	$(CC) $(CFLAGS) kernel/os_mbox.c
os_mutex.o:kernel/os_mutex.c
	$(CC) $(CFLAGS) kernel/os_mutex.c
os_sem.o:kernel/os_sem.c
	$(CC) $(CFLAGS) kernel/os_sem.c
os_time.o:kernel/os_time.c
	$(CC) $(CFLAGS) kernel/os_time.c
os_men.o:kernel/os_men.c
	$(CC) $(CFLAGS) kernel/os_men.c
os_q.o:kernel/os_q.c
	$(CC) $(CFLAGS) kernel/os_q.c
os_task.o:kernel/os_task.c
	$(CC) $(CFLAGS) kernel/os_task.c
os_flag.o:kernel/os_flag.c
	$(CC) $(CFLAGS) kernel/os_flag.c
uart0.o:user/uart0.c user/uart0.h
	$(CC) $(CFLAGS) user/uart0.c
queue.o:user/queue.c user/queue.h
	$(CC) $(CFLAGS) user/queue.c

	
###############################################################################

ucos-lpc.elf: $(START_OBJ) $(OBJS) 
	@echo + linking o file ... : $(START_OBJ) $(OBJS) "->" ucos.elf
	$(LD) $(LDFLAGS) $(START_OBJ) --start-group $(OBJS) $(LIB) --end-group -o ucos-lpc.elf
	$(BIN) -O binary ucos-lpc.elf ucos-lpc-boot.bin

	
###############################################################################

clean:
		rm -f $(TRGDIR)/*.o
		rm -f $(TRGDIR)/*.elf
		rm -f $(LSTDIR)/*.lst
		rm -f *.bin
		rm -f *~
		rm -f boot/*~
		rm -f user/*~
		rm -f lpc/*~
		rm -f lib/*~
		rm -f kernel/*~

